<?php

namespace Modules\SmallApi\Http\Controllers;

use HiCommon\Service\CheckpointMakeDateService;
use HiCommon\Service\OrderCheckpointService;
use HiCommon\Service\OrderService;
use HiCommon\Service\ShopCheckpointAppriseService;
use HiCommon\Service\ShopCheckpointProductService;
use HiCommon\Service\ShopService;
use HiCommon\Service\UsersVehicleService;
use Illuminate\Support\Facades\Request;
use Modules\Api\Service\CheckpointOrderService;

class ShopController extends BaseController
{

    /**
     * 获取已经开通的城市-以及所管辖的区
     */
    public function checkpoint_open_city_and_area()
    {
        try {
            $res = ShopService::api_open_city_and_area();
            return hello_success('成功', $res['data']);
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }


    /**
     * 检测站列表
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function checkpoint_list()
    {
        try {
            $arr_search = Request::input();
            return ShopService::api_checkpoint_list($arr_search);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }
    }

    /**
     * 检测站-商家详情
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function checkpoint_detail()
    {
        try {
            $n_id = (int)Request::input('id');
            return ShopService::api_checkpoint_detail($n_id);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }

    }

    /**
     * 检测站预约时段列表
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function checkpoint_appointment_day_list()
    {
        try {
            $n_shop_id = intval(Request::input('shop_id',0));
            $arr_where = ['checkpoint_id'=>$n_shop_id];
            return CheckpointMakeDateService::api_effective_list_by_shopid($arr_where);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }
    }

    /**
     * 车友评价列表
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function checkpoint_apprise_list()
    {
        try {
            $n_shop_id = (int)Request::input('shop_id');
            $arr_input['type'] = 11;
            $arr_input['shop_id'] = $n_shop_id;
            //获取当前门店下所有预约订单的评价
            return \HiCommon\Service\MessageServce::apprise_to_goods( $arr_input , 'checkpoint' );
//            return ShopCheckpointAppriseService::api_list_by_shopid($n_shop_id);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }
    }

//    /**
//     * 检查预约
//     *
//     * @return array|string
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function checkpoint_check_appointment()
//    {
//        $arr_search = Request::input();
//        return ShopService::checkpoint_check_appointment($arr_search);
//    }

    /**
     * 检测站价目表
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function checkpoint_product_list()
    {
        try {
            $n_shop_id = intval(Request::input('shop_id'));
            $n_use_state = intval(Request::input('use_state'));
            return ShopCheckpointProductService::api_list_by_shopid($n_shop_id,$n_use_state);
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }


    /**
     * 年检订单提交预约-到站检车-个人单
     *
     * @throws \Exception
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function order_checkpoint_submit()
    {
        try {
            $arr_input = Request::input();
            $n_uid = (int)small_api_user_id();
            $arr_user = [
              'phone'=>small_api_user()->phone,
              'realname'=>small_api_user()->realname,
            ];
            shiwu_start();
            $res = OrderCheckpointService::api_submit_personal_autonomy($n_uid,$arr_input,$arr_user);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 年检订单提交预约-代驾检车-个人单
     *
     * @throws \Exception
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function helpdriving_order_checkpoint_submit()
    {
        try {
            $arr_input = Request::input();
            $n_uid = (int)small_api_user_id();
            $arr_user = [
              'phone'=>small_api_user()->phone,
              'realname'=>small_api_user()->realname,
            ];
            shiwu_start();
            $res = OrderCheckpointService::api_submit_personal_helpdriving($n_uid,$arr_input,$arr_user);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 用户给店铺评分-年检预约单专属
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function shop_arrpise_submit()
    {
        try {
            $arr_input = Request::input();
            $n_uid = (int)small_api_user_id();
            shiwu_start();

            $res = ShopCheckpointAppriseService::api_shop_arrpise_submit_small($n_uid,$arr_input);  //使用app端的评价接口
//            $res = ShopCheckpointAppriseService::api_shop_arrpise_submit($n_uid,$arr_input);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }


    }

    /**
     * 用户年检预约单列表
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function user_checkpoint_order_list()
    {
        try {
            $n_uid = (int)small_api_user_id();
            $arr_input = Request::input();
            $arr_input['main_type'] = 1;//小程序只展示个人单，不展示企业单
            return OrderService::api_checkpoint_order_list_by_uid($n_uid,$arr_input);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }

    }

    /**
     * 用户年检预约单详情
     *
     * @return array|string
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function user_checkpoint_order_detail()
    {
        try {
            $n_uid = (int)small_api_user_id();
            $n_id = (int)Request::input('id');
            return OrderService::api_checkpoint_order_detail_for_user($n_uid,$n_id);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }
    }


    public function user_njyy_order_list(){
        try {
            $n_uid = intval(small_api_user_id());
            $arr_input = Request::input();
            $arr_input['main_type'] = 1;//小程序只展示个人单，不展示企业单
            return CheckpointOrderService::api_user_order_list($n_uid,$arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    public function user_njyy_order_detail(){
        try {
            $n_uid = intval(small_api_user_id());
            $arr_input = Request::input();
            return CheckpointOrderService::api_user_order_detail($n_uid,$arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

}